<template>
    <div class="common-container">
      <div class="header">
        <div class="header_left">
          
        </div>
        <div class="header_right">
          <el-button
          class="el_button"
            size="small"
            icon="el-icon-plus"
            style="margin-left: 15px"
            @click="addClick"
            v-permission="{ action: 'manufacturer:add' }"
          >
            新增
          </el-button>
        </div>
      </div>
      <div class="content">
        <el-table
          :data="dataList"
          height="calc(100% - 65px)"
          class="table"
          :header-cell-style="headerStyle"
        >
          <el-table-column
            align="center"
            label="序号"
            type="index"
            width="80"
            height="30"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="name"
            label="厂商名称"
            min-width="140"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            prop="username"
            label="联系人"
            min-width="140"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            prop="mobile"
            min-width="120"
            label="联系人手机"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            label="创建时间"
            min-width="140"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column align="center" label="操作" width="150">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="dark"
                content="编辑"
                placement="bottom"
                v-permission="{ action: 'manufacturer:edit' }"
              >
                <i
                  @click="editClick(scope.row)"
                  class="iconfont tianxie tableBtnIcon"
                ></i>
              </el-tooltip>
              <el-tooltip
                class="item"
                effect="dark"
                content="删除"
                placement="bottom"
                v-permission="{ action: 'manufacturer:delete' }"
              >
                <i
                  @click="delClick(scope.row.id)"
                  class="iconfont shanchu tableBtnIcon"
                ></i>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <!-- <pagination
          :page.sync="page"
          :limit.sync="limit"
          :pageSizes="[10, 20, 30, 50]"
          @pagination="getDataList"
          class="pagination"
        /> -->
      </div>
      <!--   <tenant-edit
        ref="refEdit"
        :editData="editData"
        @clearEditData="clearEditData"
      ></tenant-edit> -->
      <manufacturer-add ref="refAdd"></manufacturer-add>
      <manufacturer-edit
        ref="refEdit"
        :editData="editData"
        @clearEditData="clearEditData"
      ></manufacturer-edit>
    </div>
  </template>
  
  <script>
  import { reqManufacturerList, reqManufacturerDel } from "@api/api.js";
//   import Pagination from "../../components/Pagination.vue";
  import tableStyleMixin from "@mixin/table-style";
  import ManufacturerAdd from "./components/ManufacturerAdd.vue";
  import ManufacturerEdit from "./components/ManufacturerEdit.vue";
  // import TenantEdit from "./components/TenantEdit.vue";
  export default {
    name: "manufacturer",
    components: { ManufacturerAdd, ManufacturerEdit },
    mixins: [tableStyleMixin],
    data() {
      return {
        tenantName: "",
        loadingSearch: false, //查询按钮loading
        dataList: [],
        editData: {}, //修改数据
      };
    },
    created() {
      this.getDataList();
    },
    mounted() {},
    methods: {
      // 获取列表
      async getDataList() {
        const res = await reqManufacturerList();
        if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
        this.dataList = res.data.rows;
      },
      getInitDataList() {
        this.page = 1;
        this.limit = 10;
        this.getDataList();
      },
      // 新增
      addClick() {
        this.$refs.refAdd.dialogVisible = true;
      },
      // 编辑
      editClick(row) {
        this.editData = JSON.parse(JSON.stringify(row));
        this.$refs.refEdit.dialogVisible = true;
      },
      // 清除editData
      clearEditData() {
        this.editData = {};
      },
      // 删除
      async delClick(id) {
        const result = await this.$confirm(
          "此操作将永久删除该厂商, 是否继续?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).catch(() => {});
        if (result !== "confirm") return;
        const res = await reqManufacturerDel(id);
        if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
        this.$modal.notifySuccess("删除成功");
        this.getInitDataList();
      },
    },
  };
  </script>
  
  <style scoped lang="less">
  @import url("~@views/style/tablePage.less");
   ::v-deep .el_button.el-button--small {
      background: #7367f0;
      color: #fff;
      border: none;
  }
  </style>
  